<template>
  <div class="env-bg">
    <div class="dashboard-title">系统状态可视化</div>
    <div class="stat-group-list">
      <el-card class="group-card battery-group">
        <div class="stat-group-title">电池调度</div>
        <div class="stat-card-grid">
          <div class="stat-card-outer"><el-card shadow="hover" class="stat-card"><div class="stat-value">68%</div><div class="stat-label">电池电量(%)</div></el-card></div>
          <div class="stat-card-outer"><el-card shadow="hover" class="stat-card"><div class="stat-value bold-value">放电中</div><div class="stat-label">调度策略</div></el-card></div>
        </div>
      </el-card>
      <el-card class="group-card">
        <div class="stat-group-title">各能源发电情况</div>
        <div class="stat-card-grid">
          <div class="stat-card-outer"><el-card shadow="hover" class="stat-card"><div class="stat-value">2.5</div><div class="stat-label">太阳能发电量(kW)</div></el-card></div>
          <div class="stat-card-outer"><el-card shadow="hover" class="stat-card"><div class="stat-value">1.3</div><div class="stat-label">风能发电量(kW)</div></el-card></div>
          <div class="stat-card-outer"><el-card shadow="hover" class="stat-card"><div class="stat-value">3.1</div><div class="stat-label">国网购电量(kW)</div></el-card></div>
          <div class="stat-card-outer"><el-card shadow="hover" class="stat-card"><div class="stat-value">0.8</div><div class="stat-label">电池发电量(kW)</div></el-card></div>
        </div>
      </el-card>
      <el-card class="group-card">
        <div class="stat-group-title">运行结果</div>
        <div class="stat-card-grid">
          <div class="stat-card-outer"><el-card shadow="hover" class="stat-card"><div class="stat-value">3.9</div><div class="stat-label">当前负荷(kW)</div></el-card></div>
          <div class="stat-card-outer"><el-card shadow="hover" class="stat-card"><div class="stat-value">0.47</div><div class="stat-label">运行成本(元)</div></el-card></div>
          <div class="stat-card-outer"><el-card shadow="hover" class="stat-card"><div class="stat-value">0.032</div><div class="stat-label">碳排放量(kg)</div></el-card></div>
        </div>
      </el-card>
    </div>
    <el-card class="env-card" :body-style="{padding: '20px'}">
      <div class="chart-section">
        <div ref="lineChart" style="height: 300px;"></div>
        <el-slider v-model="time" :min="0" :max="23" show-stops style="margin-top: 20px;" />
      </div>
    </el-card>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import * as echarts from 'echarts'

const metrics = ref([
  { label: '太阳能发电量(kW)', value: 2.5 },
  { label: '风能发电量(kW)', value: 1.3 },
  { label: '电池电量(%)', value: '68%' },
  { label: '当前负荷(kW)', value: 3.9 },
  { label: '调度策略', value: '放电中' },
  { label: '运行成本(元)', value: 0.47 },
  { label: '碳排放量(kg)', value: 0.032 },
])
const time = ref(12)
const lineChart = ref(null)

onMounted(() => {
  const chart = echarts.init(lineChart.value)
  chart.setOption({
    tooltip: { trigger: 'axis' },
    legend: { data: ['太阳能', '风能', '负荷'] },
    xAxis: { type: 'category', data: Array.from({ length: 24 }, (_, i) => `${i}:00`) },
    yAxis: { type: 'value' },
    series: [
      { name: '太阳能', type: 'line', data: [0, 0.3, 1.5, 3, 5, 6, 5, 3, 2, 1, 0.5, 0.2, 0] },
      { name: '风能', type: 'line', data: [1.2, 1.5, 1.6, 1.4, 1.8, 2, 1.7, 1.5, 1.4] },
      { name: '负荷', type: 'line', data: [3, 3.2, 3.4, 3.5, 3.8, 4, 4.2, 3.8, 3.5] },
    ]
  })
})
</script>

<style scoped>
.env-bg {
  min-height: 100vh;
  background-color: #f9fbfd;
  color: #222;
  font-family: Arial, sans-serif;
  padding: 20px 0;
}
.dashboard-title {
  font-size: 26px;
  font-weight: bold;
  color: #1976d2;
  text-align: center;
  margin: 0 0 32px 0;
  letter-spacing: 2px;
}
.stat-group-list {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  justify-content: center;
  gap: 32px;
  margin-bottom: 32px;
}
/* 电池调度组单独竖排 */
.group-card.battery-group .stat-card-grid {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
}
/* 组内标题居中 */
.stat-group-title {
  font-size: 18px;
  font-weight: bold;
  color: #1976d2;
  margin-bottom: 18px;
  text-align: center;
  margin-left: 0;
}
/* 其余组为两列网格 */
.group-card {
  width: 420px;
  height: 520px;
  background: linear-gradient(to bottom right, #e3f2fd, #bbdefb);
  border-radius: 24px;
  border: 1px solid #90caf9;
  box-shadow: 0 2px 8px rgba(90, 150, 255, 0.08);
  padding: 24px 0 16px 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.group-card:not(.battery-group) .stat-card-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 32px 32px;
  justify-items: center;
  align-items: center;
  width: 100%;
  min-height: 320px;
}
.stat-card-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px 24px;
  justify-items: center;
}
.stat-card-outer {
  width: 180px;
  min-width: 150px;
  max-width: 220px;
}
.stat-card {
  text-align: center;
  background: linear-gradient(to bottom right, #e3f2fd, #bbdefb);
  border: 1px solid #90caf9;
  border-radius: 16px;
  min-height: 110px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  padding: 0 10px;
}
.stat-value {
  font-size: 32px;
  font-weight: bold;
  margin-top: 18px;
}
.bold-value {
  font-size: 36px;
  font-weight: bold;
  color: #222;
}
.stat-label {
  font-size: 16px;
  margin-top: 5px;
}
.env-card {
  background: linear-gradient(to bottom right, #e3f2fd, #bbdefb);
  border-radius: 10px;
  border: 1px solid #90caf9;
  margin: 0 auto 20px auto;
  box-shadow: 0 2px 8px rgba(90, 150, 255, 0.08);
  max-width: 1400px;
}
.card-title {
  font-size: 20px;
  font-weight: bold;
  color: #1976d2;
  display: block;
  margin-bottom: 20px;
}
.chart-section {
  padding-top: 10px;
}
</style>
